using UnityEngine.UIElements;

namespace DA.AnimGraph.Editor {
    internal class InspectorField_InputPort : InspectorField<AGAFieldModel_InputPort> {

        public string label {
            set {
                textField.label = value;
            }
            get => textField.label;
        }
        TextField textField;

        protected override void BuildUI() {
            textField = new TextField(labelText);
            textField.RegisterCallback<FocusOutEvent>(OnChange);
            textField.value = source.name;

            var textElement = textField.Q<TextElement>();
            textElement.style.marginLeft = 0; // 防止某些情况莫名其妙被设置为-2
        }

        private void OnChange(FocusOutEvent evt) {
            source.name = textField.text;
            inspectorChangeCallback?.Invoke();
        }

        protected override void DrawUI() {
            Add(textField);
            //Add(new Label(source.portUuid.ToString())); // 显示uuid,debug用
        }

    }
}
